<template>
  <div>
    <el-table
      :data="depts"
      border
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="name"
        label="部门名称"
        width="180">
      </el-table-column>
      <el-table-column
        prop="introduce"
        label="部门描述"
        width="280">
      </el-table-column>
      <el-table-column
        prop="manager"
        label="部门经理"
        width="180">
      </el-table-column>
      <el-table-column
        prop="phone"
        label="部门电话">
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作"
        width="100">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
          <el-button type="text" size="small">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      :page-sizes="[5, 10, 20]"
      :page-size="pageSize"
      :current-page="currentPage"
      layout="sizes, prev, pager, next"
      :total="total"
      @current-change = "toPage"
      @size-change = "toPageSize"
      >
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: 'MyDept',
  data () {
    return {
      depts:[],
      total:0,
      currentPage:1,
      pageSize:3
    }
  },
  mounted() {
    this.list();
  },
  methods:{
    toPage(currentPage){
      this.currentPage = currentPage;
      this.list();
    },
    toPageSize(pageSize){
      this.pageSize = pageSize;
      this.currentPage = 1;
      this.list();
    },
    list(){
      this.$http.get('/dept/lista',{"currentPage":this.currentPage, "pageSize":this.pageSize})
        .then(result=>{
          this.depts = result.data.data;
          this.total = result.data.totals;
        })
        .catch(result=>{
          this.$message.error('系统繁忙');
          console.log(result);
        })
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>
